package com.hongye.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hongye.manager.vo.GroupVo;
import com.hongye.common.response.ResponseResult;
import com.hongye.manager.mapper.GroupMapper;
import com.hongye.manager.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @Autowired
    private GroupMapper groupMapper;

    @RequestMapping("/getAll/{page}/{size}")
    public ResponseResult getAll(@PathVariable Integer page,@PathVariable Integer size){
        HashMap<String, Object> map = new HashMap<>();
        Page<GroupVo> all = groupService.getAll(new Page<>(page, size));
            map.put("data",all);
        return ResponseResult.ok(1,"成功",map);
    }

    @RequestMapping("/del")
    public ResponseResult del(Integer id){
        int i = groupMapper.deleteById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("i",i);
        return ResponseResult.ok(1,"成功",map);
    }

    @RequestMapping("/update")
    public ResponseResult update(@RequestBody GroupVo groupVo){

        GroupVo vo = new GroupVo();

        vo.setOpenStatus(groupVo.getOpenStatus());

        int upbyid = groupMapper.updateById(vo);
        HashMap<String, Object> map = new HashMap<>();
        map.put("upbyid",upbyid);
        return ResponseResult.ok(1,"成功",map);
    }

}
